package com.onegene.pdf.component.event;

import com.itextpdf.kernel.events.Event;
import com.itextpdf.kernel.events.IEventHandler;
import com.itextpdf.kernel.events.PdfDocumentEvent;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.onegene.pdf.component.paint.ColonPainting;

/**
 * 早筛每页头部
 *
 * @author laoliangliang
 * @since 2020-05-24 13:53
 */
public class ColonHeaderTextEvent implements IEventHandler {

    private PdfFont font;
    private Integer num = 0;
    private boolean isChangAi;

    public ColonHeaderTextEvent(PdfFont font, boolean isChangAi) {
        this.font = font;
        this.isChangAi = isChangAi;
    }

    @Override
    public void handleEvent(Event event) {
        PdfDocumentEvent docEvent = (PdfDocumentEvent) event;
        PdfDocument pdfDoc = docEvent.getDocument();
        ColonPainting colonPainting = new ColonPainting(pdfDoc, font, isChangAi);
        if (num % 2 == 0) {
            colonPainting.drawHeader(-5);
        } else {
            colonPainting.drawHeaderReverse(-5);
        }
        num++;
        colonPainting.close();
    }
}
